/**
 *
 */
import { defineStore } from "pinia";
import { StoreID, GlobalConfig } from "@/config";
import { persistedStateConfig } from "@/config";

/**
 * 用户状态存储
 */
export const useUserStore = defineStore(StoreID.USER_STORE, {
    state: (): UserState => {
        return {
            token: "",
            userInfo: { name: "", address: "" },
            assemblySize: "default",
            themeConfig: {
                maximize: false,
                layout: "vertical",
                primary: GlobalConfig.DEFAULT_PRIMARY,
                darkMode: true,
                greyMode: false,
                weakMode: false,
                collapse: false,
                uniqueOpened: false,
                breadcrumb: true,
                breadcrumbIcon: true,
                tabs: true,
                tabsIcon: true,
                fullScreen: true,
                fixedHeader: true,
                footer: true,
            },
        };
    },

    getters: {},

    actions: {
        /** 设置令牌 */
        setToken(token: string) {
            this.token = token;
        },
        /** 组件尺寸 */
        setAssemblySizeSize(assemblySize: AssemblySizeType) {
            this.assemblySize = assemblySize;
        },
        /** 主题配置 */
        setThemeConfig(value: ThemeConfig) {
            this.themeConfig = value;
        },
        /** 设置用户信息 */
        setUserInfo(userInfo: UserState["userInfo"]) {
            this.userInfo = userInfo;
        },

        /**
         * ?? 高级
         * @param args
         */
        setUserState(...args: ObjToKeyValArray<UserState>) {
            this.$patch({ [args[0]]: args[1] });
        },
    },

    persist: true,
});
